import { ItemData } from "../../resource/info/ItemData";
import { QuickBuyWindow } from "../common/QuickBuyWindow";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../resource/ImagesConst";
import { BaseItem } from "../common/BaseItem";
import { ItemConfig } from "../../resource/ItemConfig";
import { EBind } from "../../../../Message/Public/EBind";
import { ShopConfig } from "../../resource/ShopConfig";
import { EPrictUnit } from "../../../../Message/Public/EPrictUnit";
import { ShopRule } from "../../rules/ShopRule";
import { ObjCreate } from "../common/ObjCreate";
import { Language } from "../../../../extend/language/Language";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { Cache } from "../../cache/Cache";
import { FilterConst } from "../../../component/gconst/FilterConst";
import { ShopItemInfo } from "../../resource/info/ShopItemInfo";
import { GNumericStepper } from "../../../../com/mui/controls/GNumericStepper";
import { GButton } from "../../../../com/mui/controls/GButton";
import { _shopItem } from "../../../../this/_shopItem";
type int = number;
//class CommonBuyPropPart
    
    export  class CommonBuyPropPart /* flash.display.Sprite */
    {
        constructor(arg1: int, arg2: int)
        {
            
            this._cate = arg1;
            this._type = arg2;
            this.initUI();
            return;
        }

        public get itemData(): ItemData
        {
            return this._itemData;
        }

        public get amount(): int
        {
            return this._baseItem.amount;
        }

        public buyItem(arg1: int, arg2: Boolean=false): void
        {
            var loc1=null;
            if (arg2) 
            {
                loc1 = QuickBuyWindow.instance;
                loc1.update(this._shopItem);
                loc1.updateDefaultAmount(arg1);
                loc1.show();
            }
            else 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.ShopMallBuyItem, {"shopItemInfo": _shopItem, "amount": arg1}));
            }
            return;
        }

        protected initUI(): void
        {
            this._itemBg = GlobalClass.getBitmap(ImagesConst.PackItemBg);
            this._itemBg.x = 0;
            this._itemBg.y = 20;
            addChild(this._itemBg);
            this._baseItem = new BaseItem();
            this._baseItem.setSize(32, 32);
            this._baseItem.x = this._itemBg.x + 3;
            this._baseItem.y = this._itemBg.y + 3;
            addChild(this._baseItem);
            var loc1=ItemConfig.instance.getItemByType(this._cate, this._type, EBind._EBindNo).item.code;
            this._itemData = new ItemData(loc1);
            this._baseItem.itemData = this._itemData;
            this._baseItem.toolTipData = this._itemData.getToolTipData();
            this._shopItem = ShopConfig.instance.getGoldItemByType(this._cate, this._type, -1, EPrictUnit._EPriceUnitGold, ShopRule.ShopMallProp);
            this._itemName = ObjCreate.createTextField("", this._itemBg.x + this._itemBg.width + 4, this._itemBg.y, 120, 20, this);
            this._itemPriceTxt = ObjCreate.createTextField("", this._itemName.x, this._itemName.y + 22, 20, 20, this);
            this._itemPriceTxt.textColor = 16776960;
            this._itemPriceTxt.text = this._shopItem.tshopSell.price.toString();
            this._itemPriceBmp = GlobalClass.getBitmap(ImagesConst.Yuanbao);
            this._itemPriceBmp.x = this._itemPriceTxt.x + 32;
            this._itemPriceBmp.y = this._itemPriceTxt.y;
            addChild(this._itemPriceBmp);
            this._numStep = ObjCreate.createGNumericStepper(this._itemPriceBmp.x + this._itemPriceBmp.width + 12, this._itemPriceBmp.y - 3, 50, 20, this);
            this._buyBtn = ObjCreate.createGButton(Language.getString(26321), this._numStep.x + this._numStep.width + 10, this._numStep.y, 40, 20, this, "Button");
            this._buyBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onBuyBtnClickHandler);
            this.updatePackData();
            return;
        }

        protected onBuyBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            this.buyItem(this._numStep.value);
            return;
        }

        public updateData(arg1: ItemData): void
        {
            this._item = arg1;
            return;
        }

        public updateNeedCount(arg1: int): void
        {
            this._itemName.htmlText = this._itemData.itemInfo.htmlName + HTMLUtil.addColor("*" + arg1, this._itemData.itemInfo.colorStr);
            return;
        }

        public updatePackData(): void
        {
            var loc1=Cache.instance.pack.backPackCache.getItemCountByCategoryAndType(this._cate, this._type);
            this._baseItem.amount = loc1;
            if (loc1 != 0) 
            {
                this._baseItem.filters = null;
            }
            else 
            {
                this._baseItem.filters = [FilterConst.colorFilter];
            }
            return;
        }

        public clear(): void
        {
            this._item = null;
            this._itemName.htmlText = this._itemData.itemInfo.htmlName + HTMLUtil.addColor("*0", this._itemData.itemInfo.colorStr);
            return;
        }

        protected /* var */_itemBg: Object /* flash.display.Bitmap */;

        protected /* var */_baseItem: BaseItem;

        protected /* var */_itemData: ItemData;

        protected /* var */_shopItem: ShopItemInfo;

        protected /* var */_itemName: Object /* flash.text.TextField */;

        protected /* var */_itemPriceTxt: Object /* flash.text.TextField */;

        protected /* var */_itemPriceBmp: Object /* flash.display.Bitmap */;

        protected /* var */_numStep: GNumericStepper;

        protected /* var */_buyBtn: GButton;

        protected /* var */_item: ItemData;

        protected /* var */_cate: int;

        protected /* var */_type: int;
    }
